package com.itHaipeng.web.old;

import com.alibaba.fastjson.JSON;
import com.itHaipeng.pojo.Brand;
import com.itHaipeng.service.BrandService;
import com.itHaipeng.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/insert")
public class InsertServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json;charset=utf-8");
        //接收品牌提交过来的数据
        BufferedReader requestReader = request.getReader();
        String s = requestReader.readLine();
        Brand brand = JSON.parseObject(s, Brand.class);
        if(brand.toString()!=null){
            BrandService brandService=new BrandServiceImpl();
            brandService.insert(brand);
            response.getWriter().write("success");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
